# 插入排序
"""
0-0:有序
0-1：有序
0-2：有序
0-3：有序
......
0-(n-1):有序
"""


def swap(li, i, j):
    tmp = li[j]
    li[j] = li[i]
    li[i] = tmp



def insertsort(li):
    l = len(li)
    if not li or (l<2):
        return
    for i in range(1,l):
        newindex = i
        while (newindex-1 >= 0) and (li[newindex-1] > li[newindex]):
            swap(li,newindex,newindex-1)
            newindex -= 1
        print(li)




if __name__ == '__main__':
    li = [2, 5, 1, 6, 15, 9]
    insertsort(li)
    print(li)